export class Storage {
  storage: typeof localStorage | typeof sessionStorage
  constructor(storage: typeof localStorage | typeof sessionStorage) {
    this.storage = storage
  }
  getItem(key: string) {
    return JSON.parse(this.storage.getItem(key) as string)
  }
  setItem(key: string, value: any) {
    if (typeof value === 'object' || typeof value === 'function') {
      this.storage.setItem(key, JSON.stringify(value))
    } else {
      this.storage.setItem(key, value)
    }
  }
  removeItem(key: string) {
    this.storage.removeItem(key)
  }
  clear() {
    this.storage.clear()
  }
}
export const l = new Storage(localStorage)
export const s = new Storage(sessionStorage)
console.log(l, s)
